﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor.PackageManager.UI;
using UnityEngine;

public class OpenDoor : MonoBehaviour
{
    public bool isNearDoor = false;//是否在触发器内
    private Animator animator;//动画器引用
    public GameObject PlayerObj;//玩家引用
    private void Start()
    {
            animator = GetComponent<Animator>();
        PlayerObj = GameObject.FindGameObjectWithTag("Player");
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            isNearDoor = true;
        }
    }
    private void OnTriggerExit(Collider other)
    { 
        if (other.tag.Equals("Player")){animator.SetBool("Open", false);}
    }
    private void Update() 
    {
        if (PlayerObj == null)
        {
            Debug.LogError("玩家获取失败，请检查代码");
            return;
        }
        if (Input.GetKeyUp(KeyCode.E)) 
        {
            if(isNearDoor && PlayerObj.GetComponent<Bag>().isHasKey)
                animator.SetBool("Open", true);//开门
        }

    }
}
